home *** CD-ROM | disk | FTP | other *** search
/ KeyGen Studio 2002 / KeyGen_Studio_2002.iso / Tutorials / Eternal bliss / DEBUG2.ZIP / vbcrackme2.txt < prev    next >
Encoding:
Text File  |  1999-04-14  |  12.2 KB  |  391 lines

  1.             VBCrackMe 2 explained
  2.  
  3. Written by Etenal Bliss
  4. Email: Eternal_Bliss@hotmail.com
  5. Website: http://crackmes.cjb.net
  6.          http://surf.to/crackmes
  7. Date written: 14th April 1999
  8.  
  9. Program Details:
  10. Language: Visual Basic
  11.  
  12. Learning Method:
  13. Code Explanation
  14. SmartCheck functions
  15.  
  16. Viewing Method:
  17. Use Notepad with Word Wrap switched OFF
  18. Screen Area set to 800 X 600 pixels (Optional)
  19.  
  20. __________________________________________________________________________
  21.  
  22.                 About the Essay
  23.  
  24. This is the second of the series of explanation on how coding in VB will
  25. affect the cracking process. In these essays, I'll also show you how crackmes
  26. are generally written in VB. I've included my thought processes that went
  27. through my mind while coding for this crackme.
  28.  
  29. If you have missed the first essay, go to my website and get it. 
  30. Read it first before reading this because there are some parts 
  31. which I will not repeat here again.
  32.  
  33. To fully understand what I am describing, it would help if you have the 
  34. CrackMe running and testing certain stuff out while you read.
  35.  
  36. __________________________________________________________________________
  37.  
  38.                 About the Protection
  39.  
  40. This crackme uses a hard-coded code which is hidden using another method
  41. different from the 1st CrackMe.
  42.  
  43. This is what I wrote in the textfile for this CrackMe:
  44. "Find the correct hardcoded code in this CrackMe. I've disabled the __vbastrcomp breakpoint in
  45.  Softice and have made sure that the code is not seen explicitly in SmartCheck or in Hexeditor.
  46.  
  47.  Since this is more of a practice and taste of VB cracking, I'll give you a few hints:
  48.  1) In SmartCheck, although you will not see the REAL code, if you observe carefully, you will
  49.     see how the real code is constructed.
  50.  2) It is possible to trace in Softice."
  51.  
  52. __________________________________________________________________________
  53.  
  54.         A brief explanation on how VB coding is done...
  55.  
  56. Other than the things I mentioned in the first essay, I'd like to add some
  57. more commands that are frequently used.
  58.  
  59. Mid("word",2,1) - To get the 2nd char out of the 1st parameter ie "o"
  60. **In SmartCheck, you will see Mid() commands as well and it works the same way
  61.  
  62. Asc(x) - x can be any of the 255 characters in ascii format. It will be changed
  63.          to decimal values. Eg Asc("E") = 69
  64. **Asc() commands are also seen in SmartCheck.
  65.  
  66. & - joins up 2 strings eg "I Love " & "Cracking" = "I Love Cracking"
  67. **One possible line you will see in SC is __vbaVarCat and is followed by
  68.   __vbaVarMove. This two functions are used when the author uses "&" 
  69.   to join 2 strings together
  70.  
  71. Val - get the numbers contained in a string as a numeric value
  72. **You will see it exactly the same in SC.
  73.  
  74. For...Next - is a loop with a counter. Examples will be shown below
  75. **You will see __vbaVarForInit (initialise the loop) and __vbaVarForNext
  76.   in SmartCheck. No kidding!
  77.   
  78. __________________________________________________________________________
  79.  
  80.  
  81.                 Main Code
  82.  
  83. I've copied and pasted the main routine found in this crackme which is
  84. the protection scheme, the heart of the crackme. In the next section, I'll
  85. go into the explanation of some of the lines.
  86.  
  87.  
  88. Private Sub Command1_Click()
  89. Dim x As Variant, num As Variant, tru As Variant
  90. c = "10511532"
  91. f = "10132"
  92. On Error GoTo err2
  93. a = "116104"
  94. g = "1141019911632"
  95. x = 1
  96. b = "84104"
  97. d = "99111"
  98. e = "114"
  99. h = "100101"
  100.  
  101. If Text1.Text = "" Then
  102. Text1.Text = "You have to enter something!"
  103. GoTo err1
  104. End If
  105.  
  106. For k = 1 To 5
  107. num = num & Asc(Mid(Text1.Text, k, 1))
  108. Next k
  109.  
  110. tru = b & c
  111.  
  112. x = Val(num) - Val(tru)
  113. If x = 0 Then
  114. x = 1
  115. num = 0
  116. GoTo next1
  117. Else
  118. GoTo err2
  119. End If
  120.  
  121. next1:
  122. For k = 6 To 8
  123. num = num & Asc(Mid(Text1.Text, k, 1))
  124. Next k
  125.  
  126. tru = c
  127.  
  128. x = Val(num) - Val(tru)
  129. If x = 0 Then
  130. x = 1
  131. num = 0
  132. GoTo next2
  133. Else
  134. GoTo err2
  135. End If
  136.  
  137. next2:
  138. For k = 9 To 12
  139. num = num & Asc(Mid(Text1.Text, k, 1))
  140. Next k
  141.  
  142. tru = a & f
  143.  
  144. x = Val(num) - Val(tru)
  145. If x = 0 Then
  146. x = 1
  147. num = 0
  148. GoTo next3
  149. Else
  150. GoTo err2
  151. End If
  152.  
  153. next3:
  154. For k = 13 To 20
  155. num = num & Asc(Mid(Text1.Text, k, 1))
  156. Next k
  157.  
  158. tru = d & e & g
  159.  
  160. x = Val(num) - Val(tru)
  161. If x = 0 Then
  162. x = 1
  163. num = 0
  164. GoTo next4
  165. Else
  166. GoTo err2
  167. End If
  168.  
  169. next4:
  170. For k = 21 To Len(Text1.Text)
  171. num = num & Asc(Mid(Text1.Text, k, 1))
  172. Next k
  173.  
  174. tru = d & h
  175.  
  176. x = Val(num) - Val(tru)
  177. If x = 0 Then
  178. Text1.Text = "You have solved it! Good Work!"
  179. Text1.Enabled = False
  180. Command1.Enabled = False
  181. Command3.Enabled = True
  182. Command3.Caption = "&Again!"
  183. Command2.SetFocus
  184. GoTo err
  185. Else
  186. GoTo err2
  187. End If
  188.  
  189. err2:
  190. Text1.Text = "Wrong! Try Again!!"
  191. err1:
  192. Text1.Enabled = False
  193. Command1.Enabled = False
  194. Command3.Enabled = True
  195. Command3.SetFocus
  196. err:
  197. End Sub
  198.  
  199.  
  200. __________________________________________________________________________
  201.  
  202.  
  203.                 Code Explanation
  204.  
  205. 1) Dim x As Variant, num As Variant, tru As Variant
  206. ===================================================
  207. x, num and tru are variables. Variables are like containers that can contain
  208. values. Depending on the type of values required, the "containers" will
  209. have to be initialised to make sure that they can contain the values required.
  210. Using "Dim", x, num and tru are initialised to contain values of Variant type.
  211. This will be useful later.
  212.  
  213.  
  214. 2) c = "10511532"
  215.    f = "10132"
  216.    On Error GoTo err2
  217.    a = "116104"
  218.    g = "1141019911632"
  219.    x = 1
  220.    b = "84104"
  221.    d = "99111"
  222.    e = "114"
  223.    h = "100101"
  224. ============================================
  225. These lines are actually the answer to the CrackMe. Doesn't look like it, right?
  226. That is what I meant when I said I hide the hardcoded code using another method.
  227. The numbers shown here are actually decimal values of the correct code.
  228. Therefore,
  229. c = "is "
  230. f = "e "
  231. a = "th"
  232. g = "rect "
  233. b = "Th"
  234. d = "co"
  235. e = "r"
  236. h = "de"
  237.  
  238. The value of x is 1 and will be used later.
  239.  
  240.  
  241. 3) If Text1.Text = "" Then
  242.    Text1.Text = "You have to enter something!"
  243.    GoTo err1
  244.    End If
  245. ==============================================
  246. This part of the code is to make sure the the user enter something.
  247. If the text in textbox 1 is blank, it will be considered "".
  248. Then, "You have to enter something!" will be shown in the textbox.
  249. "GoTo err1" just tells the CrackMe to go to the end of the code where the pointer
  250. "err1:" is found. That will end the whole routine.
  251. Notice that this uses the String compare routine and will break on __vbaStrComp
  252.  
  253.  
  254. 4) For k = 1 To 5
  255.    num = num & Asc(Mid(Text1.Text, k, 1))
  256.    Next k
  257. ==============================================
  258. This is a loop set to run 5 times ("For k = 1 To 5")
  259. The next line is actually contains 3 functions:
  260. a) Mid(Text1.Text, k, 1)
  261.    To get the kth char from the text you entered. 
  262.    "1" is to signify the number of char to retrieve starting from the kth
  263. b) Asc()
  264.    Since a char would have been retrieved in the Mid() function, 
  265.    Asc() will convert that to its decimal value.
  266. c) num = num & Asc()
  267.    What this does is to join up the result of converting the char to decimal value
  268.    with anything in the "num" variable.
  269.  
  270. So, the overall function of this 3 lines is to
  271. convert the 1st to the 5th char of what you entered to their decimal values
  272. and join them up. eg. ABCDE = 6566676869
  273.  
  274. Now, do you understand why I convert them to decimal? Do you remember that I had the
  275. correct code in decimal values? Instead of converting the correct value into ascii format
  276. and directly compares with what you entered, it would be slightly more difficult 
  277. if I change what YOU type into something else. So, you will NEVER see the correct code in
  278. ascii format! 8)
  279.  
  280.  
  281. 5) tru = b & c
  282. ==============================================
  283. Now that "num" contains what you typed. 
  284. "tru" will actually contain the correct 1st 5 chars.
  285. notice it is "b & c" which will combine 84104 and 10511532 together.
  286. Note: it is not ADDITION but just joining to form 8410410511532
  287. If I were to convert it to ascii format, it will be "This "
  288.  
  289. 6) x = Val(num) - Val(tru)
  290.    If x = 0 Then
  291.    x = 1
  292.    num = 0
  293.    GoTo next1
  294.    Else
  295.    GoTo err2
  296.    End If
  297. ==============================================
  298. This is the comparison routine with a twist.
  299.  
  300. Instead of comparing "num" with "tru" using "If num = tru Then" line,
  301. I get the value of "num" and "tru" and subtract them against each other.
  302. The effect? Well, if they are the same, the result in "x" will be 0!
  303.  
  304. Then "If x = 0 Then" line actually implies that if value in "num" is
  305. equal to value in "tru", then proceed to the pointer "next1:"
  306. otherwise ("Else") go to the pointer "err2:" to be shown a message.
  307. And followed by a "End If" to show that it is the end of this query.
  308.  
  309. Remember that at the start, I initialised "x" to be a container carrying
  310. Variant type data? When I used "If x = 0 Then", I am calling the function
  311. to compare variants and will result in the breakpoint __vbaVarTstEq to break
  312. in Softice. Since it is vb6, you will have to type msvbvm60! in front. 
  313. In SC, you will see lines with __vbaVarTstEq too. 8)
  314.  
  315. I said I have disabled __vbaStrComp, this is what I meant. I simply did not
  316. use the String comparison routine. 8)
  317.  
  318. Now, since I know that this breakpoint works, if I were to use
  319. "If num = tru Then" line instead of subtracting them first and comparing
  320. the result with 0, when a cracker breaks using __vbaVarTstEq, 
  321. he would be able to sniff out the value of num and tru because they are
  322. comparing directly with each other!
  323.  
  324. That is the reason why I code this comparison routine this way...
  325. Subtracting the entered value with the correct value to see if the result is 0.
  326. So, even if you were to break using this function, you will see some value compared
  327. with 0 but never the correct characters. Nice? 8P
  328.  
  329.  
  330. The next few sections in the code mirrors what I have described in 5 and 6.
  331. Comparing word by word for the correct code. When the word is incorrect,
  332. the crackme will jump to the "err2:" pointer and the textbox will show
  333. "Wrong! Try Again!!"
  334.  
  335. If every word is correct, you will continue smoothly down the lines until
  336. you are shown "You have solved it! Good Work!".
  337.  
  338. __________________________________________________________________________
  339.  
  340.         How to Crack such VB protection schemes
  341.  
  342. In the first CrackMe, it used String compare thus __vbaStrComp is the 
  343. breakpoint. In this CrackMe, Variant Compare is used and thus __vbaStrComp
  344. will not break on the compare routine although it will at the line
  345. "If Text1.Text = "" Then".
  346.  
  347. In VB, the function to compare variants is __vbaVarTstEq (VARiant TeST EQual)
  348. So, in Softice, setting the breakpoint using "bpx msvbvm60!__vbaVarTstEq" 
  349. (or msvbvm60!__vbaVarTstEq)
  350. will cause Softice to break when the Cracker click on the "Register" button.
  351. msvbvm60! is added in front because this CrackMe is written in VB6.
  352.  
  353. The codes used in the dll for this compare will also be the same so, it will
  354. be quite useful if you get used to them.
  355.  
  356. There are functions such as __vbaVarTstGt, __vbaVarTstNe and I leave it up
  357. to you to discover what they mean. Just looking at them would give you a hint.
  358. 8)
  359.  
  360. __________________________________________________________________________
  361.  
  362.             Additional points
  363.  
  364.  
  365. For other breakpoints and compare methods, you can get my two essays on VB
  366. cracking found on my website.
  367.  
  368. SmartCheck logfile with the source is included together with this textfile
  369. "Debug2.zip". Unzip everything in it and double click on the debug2.sce file. 
  370.  
  371. If you have installed SmartCheck, SmartCheck will open up and the usual
  372. lot of information is shown. However, in this case, since the source code is
  373. included, when you click on threads in Command1_Click line, you will see
  374. how the source code is processed and how it is presented in SmartCheck.
  375. A definite learning experience for those who are struggling with SmartCheck usage.
  376. The first Command1_Click shows the lines processed when the correct code is
  377. entered. The second Command1_Click shows the lines processed when the code
  378. entered is wrong.
  379.  
  380. __________________________________________________________________________
  381.  
  382.                 End of File
  383.  
  384. I would like to thank Jeff for giving me this idea of writing essays on how
  385. I created my CrackMe, what commands will result in what breakpoints to use
  386. in Softice and how SmartCheck's usefulness is exploited.
  387.  
  388. All the best to those reading this essay in VB cracking!
  389.  
  390.  
  391.